/*
 * Copyright (c) 2024 Soon.Liao. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * @Author: soon.liao
 * @Date: 2024-11-02 08:51:27
 * @LastEditors: soon.liao
 * @LastEditTime: 2024-11-02 10:03:02
 * @FilePath: \user\i2c_common\src\i2c_common.c
 * @Description: Create Date : 2024
 * NA
 */
#include "main.h"
#include "debug.h"
#include "i2c_common.h"

static volatile int g_tx_done_flag = BASE_CFG_UNSET;
static volatile int g_rx_done_flag = BASE_CFG_UNSET;
static volatile int g_error_flag = BASE_CFG_UNSET;

/**
 * @brief I2c dma sample tx callback handle.
 * @param handle I2c handle.
 * @retval None.
 */
void common_i2c0_tx_callback(I2C_Handle *handle)
{
    BASE_FUNC_UNUSED(handle);
    g_tx_done_flag = BASE_CFG_SET;
}

/**
 * @brief I2c dma sample rx callback handle.
 * @param handle I2c handle.
 * @retval None.
 */
void common_i2c0_rx_callback(I2C_Handle *handle)
{
    BASE_FUNC_UNUSED(handle);
    g_rx_done_flag = BASE_CFG_SET;
}

/**
 * @brief I2c dma sample Error callback handle.
 * @param handle I2c handle.
 * @retval None.
 */
void common_i2c0_error_callback(I2C_Handle *handle)
{
    BASE_FUNC_UNUSED(handle);
    g_error_flag = BASE_CFG_SET;
    DBG_PRINTF("LINE:%d,Common_I2C0ErrorCallback\r\n", __LINE__);
}

int get_tx_done_flag(void)
{
    return g_tx_done_flag;
}

int get_rx_done_flag(void)
{
    return g_rx_done_flag;
}

int get_error_flag(void)
{
    return g_error_flag;
}

void set_tx_done_flag(int val)
{
    g_tx_done_flag = val;
}

void set_rx_done_flag(int val)
{
    g_rx_done_flag = val;
}

void set_error_flag(int val)
{
    g_error_flag = val;
}
